--[[

    Copyright (c) 2012-2020 baby-bus.com

    TODO:   ClassName
    Author: DemonYao
    Date:   2020.10.14
 
    http://www.babybus.com/ 

]] 




--------------------------
-- 引入命名空间
--------------------------
-- local BaseLayer = import("app.common.layer.BaseLayer")




--[[
    类
--]]


local M = class("Robot", require("app.common.DragonBones"))


local JUMP_SPEED             = 20
local NORMALIZE_MOVE_SPEED   = 3.6
local MAX_MOVE_SPEED_FRONT   = NORMALIZE_MOVE_SPEED * 1.4
local MAX_MOVE_SPEED_BACK    = NORMALIZE_MOVE_SPEED * 1.0
local NORMAL_ANIMATION_GROUP = "normal"
local AIM_ANIMATION_GROUP    = "aim"
local ATTACK_ANIMATION_GROUP = "attack"
local WEAPON_L_LIST          = {"weapon_1502b_l", "weapon_1005", "weapon_1005b", "weapon_1005c", "weapon_1005d", "weapon_1005e", ""}
local WEAPON_R_LIST          = {"weapon_1502b_r", "weapon_1005", "weapon_1005b", "weapon_1005c", "weapon_1005d", ""}
local SKINS                  = {"mecha_1502b", "skin_a", "skin_b", "skin_c"}
--------------------------
-- 构造函数
--------------------------

function M:ctor(params)
    -- [超类调用]
    M.super.ctor(self, params)
    

    -- [本类调用]
    self._faceDir = 1
    self._isJumpingA      = false
    self._isSquating      = false
    self._isAttackingA    = false
    self._isAttackingB    = false
    self._weaponRIndex    = 0
    self._weaponLIndex    = 0
    self._skinIndex       = 0
    self._faceDir         = 1
    self._aimDir          = 0
    self._moveDir         = 0
    self._aimRadian       = 0.0
    self._speedX          = 0.0
    self._speedY          = 0.
    self._armature        = ni
    self._armatureDisplay = ni
    self._weaponL         = nil
    self._weaponR         = nil
    self._aimState        = null
    self._walkState       = null
    self._attackState     = null
end

--------------------------
-- 渲染
--------------------------

function M:onRender()
    -- [超类调用]
    M.super.onRender(self)

end 



-- 加载渲染以外的其他操作
function M:onEnterTransitionFinish()
    --触控n
    self:bindTouch() 
    self:getWeaponSlot()
end

-- 获取武器的插槽
function M:getWeaponSlot()
    self.weaponL = self:getSlot("weapon_l"):getChildArmature():getEventDispatcher()
    self.weaponR = self:getSlot("weapon_r"):getChildArmature():getEventDispatcher()
end

function M:animationEventHandler(eventObject)
    if eventObject.type == "start" then

    elseif eventObject.type == "loopComplete" then

    elseif eventObject.type == "complete" then

    elseif eventObject.type == "fadeIn" then       

    elseif eventObject.type == "fadeInComplete" then

    elseif eventObject.type == "fadeOut" then

    elseif eventObject.type == "fadeOutComplete" then

    elseif eventObject.type == "frameEvent" then

    elseif eventObject.type == "soundEvent" then

    end
end

function M:frameEventHandler(eventObject)

end 

function M:updateAnimation()
    if (self._isJumpingA) then
        return
    end

    local armature = self:getArmature()

    local animation  = self:getAnimation()
    if (self._isSquating) then
        self._speedX = 0
        local animationState = animation:fadeIn("squat", -1.0, -1,0, NORMAL_ANIMATION_GROUP)
        animationState.resetToPose = false
        self._walkState = nil
        return
    end

    if (self._moveDir == 0) then 
        self._speedX = 0
        local animationState = animation:fadeIn("idle", -1.0, -1, 0,NORMAL_ANIMATION_GROUP)
        animationState.resetToPose = false
        self._walkState = nil
    else 
        if (self._walkState == nil) then
            self._walkState =   animation:fadeIn("walk", -1.0, -1, 0, NORMAL_ANIMATION_GROUP)

            self._walkState.resetToPose = false
        end

        if (self._moveDir * self._faceDir > 0) then
            self._walkState.timeScale = MAX_MOVE_SPEED_FRONT / NORMALIZE_MOVE_SPEED
        else 
            self._walkState.timeScale = -MAX_MOVE_SPEED_BACK / NORMALIZE_MOVE_SPEED
        end

        if (self._moveDir * self._faceDir > 0) then
            self._speedX = MAX_MOVE_SPEED_FRONT * self._faceDir
        else 
            self._speedX = -MAX_MOVE_SPEED_BACK * self._faceDir
        end
    end
end

--------------------------
-- 触控
-------------------------- 

function M:onTouchBegan(x, y, touches)
    --  触控有效
    return SIGN_TOUCH_BEGAN_SWALLOWS 
end

function M:onTouchMoved(x, y, touches)
    --  
end

function M:onTouchEnded(x, y, touches)
    --  
end








--------------------------
-- 功能函数
--------------------------




--------------------------
-- 属性
--------------------------




--------------------------
-- 父类重写
--------------------------




----------------------------------------------------
-- 析构
--------------------------

function M:onDestructor()
    -- [超类调用]
    M.super.onDestructor(self)
    -- [本类调用]

end








return M






